home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 6 / The Arsenal Files 6 (Arsenal Computer).ISO / prg_casm / struc.zip / STRUC-C.CPP < prev    next >
C/C++ Source or Header  |  1996-02-02  |  2KB  |  78 lines

  1. // This code is best compiled using:
  2. //  bcc32 -WX -B -3 filename filename.asm
  3.  
  4. #include <iostream.h>
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8.  
  9. // define a structure of various size elements.
  10. struct mystruct{
  11.   char              c;
  12.   unsigned char    uc;
  13.   short             s;
  14.   unsigned short   us;
  15.   long              l;
  16.   unsigned long    ul;
  17.   char string   [200];
  18.   } struct_out;
  19.  
  20. // This will be a simple function for preformatting our screen.
  21. void format();
  22.  
  23. // The assembler routine must  be  declared  as "extern" and I'll use the
  24. //  "C" type calling convention,  since  I concider it much easier to not
  25. //  have to fiddle with the leading  underscores in code of this type.
  26. extern "C" void fill_struct (mystruct *);
  27.  
  28. main()
  29. {
  30.     format();              
  31.     
  32. // Declare a pointer of a type to match my C++ structure    
  33.     mystruct * struct_ptr;
  34.  
  35. // And assign the address of the copy of this structure that I'll be dealing
  36. //  with here.
  37.     struct_ptr = &struct_out;
  38.  
  39. // Now I'm going to call the assembler function, passing it a pointer to the
  40. //  structure within this module.
  41.     fill_struct (struct_ptr);
  42.     
  43. // These  are  the  screen  printing  routines.  They look a bit sloppy here,    
  44. //  but  I  wasn't  sure  how  to  keep this source any more tidy, and still
  45. //  deal with line wrap when others view this code.
  46.     cout << "The values below are those passed to the \"C\" structure\n"
  47.             "from within the assembler routine.\n\n";
  48.     
  49.     cout << "char          : " << (int)struct_out.c << "        to " 
  50.          << -((int)struct_out.c) << "  ascii character ' ~ '" << endl
  51.          
  52.          << "unsigned char : " << (int)struct_out.uc << endl
  53.          
  54.          << "short         : " << struct_out.s << "      to " 
  55.          << -struct_out.s << endl 
  56.          
  57.          << "unsigned short: " << struct_out.us  << endl
  58.          
  59.          << "long          : " << struct_out.l << " to " << -struct_out.l 
  60.          << endl 
  61.          
  62.          << "unsigned long : " << struct_out.ul << endl;
  63.          cout << struct_out.string;
  64.   
  65.   getch ();
  66.   clrscr();
  67.   return 0;
  68. }
  69.  
  70. void format()
  71. {
  72.    clrscr();
  73.    for(int a = 0; a < 10; a++) cout << endl;
  74. }
  75.  
  76.  
  77.  
  78.